﻿using System;
using System.Collections.Generic;
using NHunspell;

namespace KnowledgeSource
{
    public class SpellChecker //: IKnowledgeSource
    {
        
        private Hunspell hunspell;
        private Utils util;

        public SpellChecker(Hunspell hunspell)
        {
            this.hunspell = hunspell;
            this.util = new Utils() ;
        }

        public List<String> execute( string input )
        {
            var sentence = util.MakeListStringFromSentence(input);
            var possibleResults = new List<List<string>>();
            int actualWord = 0;
            try
            {
                foreach (var word in sentence)
                {
                   
                    possibleResults.Add(new List<string>());
                    if (hunspell.Spell(word) == true)
                    {
                        var x = new List<string>();
                        x.Add(word);
                        possibleResults[actualWord].AddRange(x); 
                    }
                    else
                    {
                        var suggestedWords = hunspell.Suggest(word);
                        possibleResults[actualWord].AddRange(suggestedWords);
                       
                    }
                    actualWord++;
                }

                var temp = util.CreateSentenceFromAllPosibilities(possibleResults);
                return temp;
            }
            catch (Exception ex)
            {
                var t = new List<string>();
                t.Add(input);
                return t;
            }   
        }

    }
}
